<?php
class lang
{
    public static function get($key)
    {
        $key = strtolower($key);
        $words['udnmovies.info'] = array();
        $words['getmovielinks.com'] = array();
        $words['earnmovie.com'] = array();
        $words['moviezfind.com'] = array();
        $words['moviezhunt.com'] = array();
        $words['ttmoviez.com'] = array();
        $words['udnmovies.com'] = array();

        /************* SEO ****************/

        $words['udnmovies.info']['seo_keywords_home'] = 'Torrent Download, DVDRip, HD 720p, 1080p, BRRip, HDTV, Bluray, 3D, subs, full movie watch online, AVI, MKV';
        $words['udnmovies.com']['seo_keywords_home'] = 'تحميل تورنت، ديفيدي،  عالي الدقة، بلوراي، ثلاثي الأبعاد، مترجم، تحميل ترجمة، مشاهدة اونلاين،DVDRip, HD 720p, 1080p ';


        $words['udnmovies.info']['seo_keywords_movie'] = 'Torrent Download, DVDRip, HD 720p, 1080p, BRRip, HDTV, Bluray, 3D, subs, full movie watch online, AVI, MKV';
        $words['getmovielinks.com']['seo_keywords_movie'] = 'DVDRip, Torrent Download, HD 720p, 1080p, BRRip, HDTV, Bluray, 3D, subs, full movie watch online, AVI, MKV';
        $words['earnmovie.com']['seo_keywords_movie'] = 'BRRip, Torrent Download, DVDRip, HD 720p, 1080p,  HDTV, Bluray, 3D, subs, full movie watch online, AVI, MKV';
        $words['moviezfind.com']['seo_keywords_movie'] = 'Watch Online Full Movie, BRRip, Torrent Download, DVDRip, HD 720p, 1080p,  HDTV, Bluray, 3D, subs, AVI, MKV';
        $words['udnmovies.com']['seo_keywords_movie'] = 'torrent تحميل تورنت، ديفيدي،  عالي الدقة، بلوراي، ثلاثي الأبعاد، مترجم، تحميل ترجمة، مشاهدة اونلاين،DVDRip, HD 720p, 1080p ';

        $words['udnmovies.info']['seo_keywords_person'] = 'Movies Download Picture Gallery';
        $words['udnmovies.com']['seo_keywords_person'] = 'تحميل افلام تورنت صور';

        $words['udnmovies.info']['seo_description_movie'] = 'Full Movie High speed download links for both direct and torrent downloads with subtitles';
        $words['moviezfind.com']['seo_description_movie'] = 'English Subtitles, Full Movie High speed download links for both direct and torrent downloads with subtitles';
        $words['udnmovies.com']['seo_description_movie'] = 'تحميل حصريا بروابط تورنت ومباشرة على أكثر من سيرفر مجانا وبسرعات عالية مع الترجمة العربية';


        $words['udnmovies.info']['seo_url_movie'] = '-Torrent-Download-dvdrip-brrip-720p-1080p-subs-bluray-3d-full-movie-MKV';
        $words['udnmovies.com']['seo_url_movie'] = 'torrent-full-movie-تحميل-تورنت-dvdrip-brrip-720p-1080p-subs-bluray-3d';



        /******************** Movie Page words *********************/
        $words['udnmovies.info']['torrent_download'] = "Torrent Download";
        $words['udnmovies.com']['torrent_download'] = "تحميل تورنت";

        $words['udnmovies.info']['plot'] = "Plot";
        $words['udnmovies.com']['plot'] = "القصة";

        $words['udnmovies.info']['cast'] = "Cast";
        $words['udnmovies.com']['cast'] = "طاقم الممثلين";

        $words['udnmovies.info']['download_seasons'] = "Download Seasons &amp; Episodes";
        $words['udnmovies.com']['download_seasons'] = "تحميل المواسم والحلقات";

        $words['udnmovies.info']['gallery'] = "Photo Gallery";
        $words['udnmovies.com']['gallery'] = "معرض الصور";

        $words['udnmovies.info']['similar'] = "Similar Movies";
        $words['udnmovies.com']['similar'] = "أفلام مشابهة";

        $words['udnmovies.info']['reviews'] = "User Reviews";
        $words['udnmovies.com']['reviews'] = "مراجعات الأعضاء";

        $words['udnmovies.info']['find_similar'] = "Find Movies Similar to";
        $words['udnmovies.com']['find_similar'] = "الأفلام المشابهة لـ";

        /******************** Person Page words *********************/
        $words['udnmovies.info']['all_person_movies'] = "All Movies for";
        $words['udnmovies.com']['all_person_movies'] = "جميع أفلام";

        $words['udnmovies.info']['profile'] = "Profile";
        $words['udnmovies.com']['profile'] = "السيرة";

        $words['udnmovies.info']['cast'] = "Cast";
        $words['udnmovies.com']['cast'] = "طاقم الممثلين";

        $words['udnmovies.info']['filmography'] = "Filmography";
        $words['udnmovies.com']['filmography'] = "الأعمال السينمائية";

        /******************** Home Page words *********************/
        $words['udnmovies.info']['home_title'] = "UDNMovies - Your Ultimate Movie Guide";
        $words['udnmovies.com']['home_title'] = "UDNMovies - دليلك الأمثل للأفلام";

        $words['udnmovies.info']['home_1'] = "Welcome to UDNMovies, your ultimate movie guide and the best source for movie torrents download!";
        $words['udnmovies.info']['home_2'] = "Here you will have access to over 800,000 movies to download torrents in different formats (DVDRip, HD 720p, Full HD 1080p, 3D, Soundtracks, Subtitles, and more!";
        $words['udnmovies.info']['home_3'] = "We Recommend using uTorrent client to download. Do not forget to like us using the like button at the top right! enjoy downloading.";


        $words['udnmovies.com']['home_1'] = "مرحبا بك في UDNMovies، دليلك الأمثل للبحث ومشاهدة وتحميل الأفلام عن طريق التورنت!";
        $words['udnmovies.com']['home_2'] = "هنا سوف تجد اكثر من 800,000 فيلم للتحميل بصيغ مختلفة  DVDRip, HD 720p, Full HD 1080p وثلاثي الأبعاد بالإضافة الى صوتيات والترجمة العربية وغيرها!";
        $words['udnmovies.com']['home_3'] = "ننصح باستخدام برنامج يو تورنت uTorrent لتحميل الأفلام. لاتنسى ان تعطينا لايك! على الفيسبوك! استمتع بوقتك!";

        $words['udnmovies.info']['home_playing'] = "Now Playing";
        $words['udnmovies.com']['home_playing'] = "الآن في السينما";

        $words['udnmovies.info']['home_highest'] = "Highest Rated 2013 Movies";
        $words['udnmovies.com']['home_highest'] = "الأعلى تقييما في 2013";

        $words['udnmovies.info']['home_100'] = "Overall Top 100 Movies";
        $words['udnmovies.com']['home_100'] = "الأعلى تقييما عالمياً";

        $words['udnmovies.info']['home_oscar'] = "Latest Oscar Awards Winners";
        $words['udnmovies.com']['home_oscar'] = "الحائزون على جائزة الأوسكار";

        $words['udnmovies.info']['home_bestpic'] = "Latest Best Picture Awards Winners";
        $words['udnmovies.com']['home_bestpic'] = "الحائزون على جائزة أفضل صورة";

        $words['udnmovies.info']['home_golden'] = "Latest Golden Globe Awards Winners";
        $words['udnmovies.com']['home_golden'] = "الحائزون على جائزة جولدن جلوب";

        $words['udnmovies.info']['home_emmy'] = "Latest Emmy Awards Winners";
        $words['udnmovies.com']['home_emmy'] = "الحائزون على جائزة إيمي";

        $words['udnmovies.info']['home_soon'] = "Coming Soon";
        $words['udnmovies.com']['home_soon'] = "قريبا في السينما";

        $words['udnmovies.info']['view_more'] = "View More...";
        $words['udnmovies.com']['view_more'] = "مشاهدة المزيد...";

        /******************** Download Page words *********************/
        $words['udnmovies.info']['sorry_1'] = "Sorry We Could Not find";
        $words['udnmovies.info']['sorry_2'] = "Do not worry! You can request this movie torrent! we will find it, make it available, and send you an email! Make sure you check back as our torrents are updated daily.";

        $words['udnmovies.com']['sorry_1'] = "نأسف  لعدم وجود نتائج لـ";
        $words['udnmovies.com']['sorry_2'] = "لاتقلق! بإمكانك طلب التورنت لهذا الفيلم! سوف نبحث عنه ونتأكد من توفيره للتحميل ومن ثم سنرسل لك رسالة عبر البريد الإلكتروني! تأكد من زيارتك موقعنا مرة أخرى حيث أن الروابط يتم تحديثها يومياً.";

        $words['udnmovies.info']['email'] = "Your Email:";
        $words['udnmovies.com']['email'] = "بريدك الإلكتروني:";

        $words['udnmovies.info']['format'] = "Format";
        $words['udnmovies.com']['format'] = "الصيغة";

        /******************** Browse/Search Page words *********************/
        $words['udnmovies.info']['genres'] = "Genres";
        $words['udnmovies.com']['genres'] = "تصنيفات";

        $words['udnmovies.info']['search'] = "Search";
        $words['udnmovies.com']['search'] = "بحث";

        $words['udnmovies.info']['favorites'] = "Add To </br> Favorites";
        $words['udnmovies.com']['favorites'] = "أضف إلى </br> المفضلة";

        $words['udnmovies.info']['tv-series'] = "TV Series";
        $words['udnmovies.info']['action'] = "Action";
        $words['udnmovies.info']['animation'] = "Animation";
        $words['udnmovies.info']['drama'] = "Drama";
        $words['udnmovies.info']['adventure'] = "Adventure";
        $words['udnmovies.info']['biography'] = "Biography";
        $words['udnmovies.info']['comedy'] = "Comedy";
        $words['udnmovies.info']['crime'] = "Crime";
        $words['udnmovies.info']['documentary'] = "Documentary";
        $words['udnmovies.info']['family'] = "Family";
        $words['udnmovies.info']['fantasy'] = "Fantasy";
        $words['udnmovies.info']['film-noir'] = "Film-Noir";
        $words['udnmovies.info']['game-show'] = "Game-Show";
        $words['udnmovies.info']['history'] = "History";
        $words['udnmovies.info']['horror'] = "Horror";
        $words['udnmovies.info']['music'] = "Music";
        $words['udnmovies.info']['musical'] = "Musical";
        $words['udnmovies.info']['mystery'] = "Mystery";
        $words['udnmovies.info']['news'] = "News";
        $words['udnmovies.info']['reality-tv'] = "Reality-TV";
        $words['udnmovies.info']['romance'] = "Romance";
        $words['udnmovies.info']['sci-fi'] = "Sci-Fi";
        $words['udnmovies.info']['sport'] = "Sport";
        $words['udnmovies.info']['talk-show'] = "Talk-Show";
        $words['udnmovies.info']['thriller'] = "Thriller";
        $words['udnmovies.info']['war'] = "War";
        $words['udnmovies.info']['western'] = "Western";

        $words['udnmovies.com']['tv-series'] = "مسلسلات";
        $words['udnmovies.com']['action'] = "أكشن";
        $words['udnmovies.com']['animation'] = "رسوم - أنيميشن";
        $words['udnmovies.com']['drama'] = "دراما";
        $words['udnmovies.com']['adventure'] = "مغامرة";
        $words['udnmovies.com']['biography'] = "سيرة";
        $words['udnmovies.com']['comedy'] = "كوميدي";
        $words['udnmovies.com']['crime'] = "جريمة";
        $words['udnmovies.com']['documentary'] = "وثائقي";
        $words['udnmovies.com']['family'] = "عائلي";
        $words['udnmovies.com']['fantasy'] = "فنتازيا";
        $words['udnmovies.com']['film-noir'] = "فيلم-نوار";
        $words['udnmovies.com']['game-show'] = "برنامج";
        $words['udnmovies.com']['history'] = "تاريخي";
        $words['udnmovies.com']['horror'] = "رعب";
        $words['udnmovies.com']['music'] = "موسيقى";
        $words['udnmovies.com']['musical'] = "موسيقي";
        $words['udnmovies.com']['mystery'] = "غموض";
        $words['udnmovies.com']['news'] = "أخبار";
        $words['udnmovies.com']['reality-tv'] = "واقعي";
        $words['udnmovies.com']['romance'] = "رومانسي";
        $words['udnmovies.com']['sci-fi'] = "خيال علمي";
        $words['udnmovies.com']['sport'] = "رياضة";
        $words['udnmovies.com']['talk-show'] = "برنامج محادثة";
        $words['udnmovies.com']['thriller'] = "إثارة";
        $words['udnmovies.com']['war'] = "حرب";
        $words['udnmovies.com']['western'] = "غربي";

        $domain = str_replace("www.","",$_SERVER['SERVER_NAME']);

        if($domain == 'localhost')
            $domain = 'udnmovies.info'; //test locally

        if($words[$domain][$key] == null)
            $domain = 'udnmovies.info'; //all other domains will use trendx if they have no entries

        return $words[$domain][$key];
    }
    public static function translate_jsonp($text)
    {
        $contents = lang::translate($text);
        return 'callback('.$contents.');';
    }
    public static function translate($text)
    {
        /*
                $length = strlen($text);
                $output = '';
                if($length > 500)
                {
                    $pcs = explode('.', $text);
                    $i=0;
                    while($i<count($pcs))
                    {
                        $len = 0;
                        $str='';
                        while($len<500 && $i<count($pcs))
                        {
                            if(strlen($str)+strlen($pcs[$i]) < 500)
                                $str.=$pcs[$i];
                            $i++;
                            $len+=strlen($pcs[$i]);
                        }
                        $output.=lang::get_bing($str);
                    }
                    return $output;
                }
                else*/
        return lang::get_bing($text);
    }
    public static function get_babylon($text)
    {
        //http://translation.babylon.com/translate/babylon.php?v=1.0&q=<TEXT-TO-TRANSLATE>&langpair=0%7C15&callback=babylonTranslator.callback&context=babylon.0.15._babylon_api_response
        $babylon_url = "http://translation.babylon.com/translate/babylon.php?v=1.0&q=".$text."&langpair=0%7C15&callback=babylonTranslator.callback&context=babylon.0.15._babylon_api_response";
        $contents = file_get_contents($babylon_url);
        $open = strpos($contents,'{');
        $close = strpos($contents,'}');
        $length = $close - $open;
        $contents = substr($contents, $open, $length + 1);
        $contents = json_decode($contents,true);
        return $contents['translatedText'];
    }
    public static function get_bing($text)
    {
        try {
            //Client ID of the application.
            $clientID       = "udn";
            //Client Secret key of the application.
            $clientSecret = "z27AAbjIzFi9N5NljmnqN8XVPPyGhdQxbhCrnh51TH4";
            //OAuth Url.
            $authUrl      = "https://datamarket.accesscontrol.windows.net/v2/OAuth2-13/";
            //Application Scope Url
            $scopeUrl     = "http://api.microsofttranslator.com";
            //Application grant type
            $grantType    = "client_credentials";
            //Create the AccessTokenAuthentication object.
            $authObj      = new AccessTokenAuthentication();
            //Get the Access token.
            $accessToken  = $authObj->getTokens($grantType, $scopeUrl, $clientID, $clientSecret, $authUrl);
            //Create the authorization Header string.
            $authHeader = "Authorization: Bearer ". $accessToken;
            //Set the params.//
            $fromLanguage = "en";
            $toLanguage   = "ar";
            $inputStr     = $text;
            $contentType  = 'text/plain';
            $category     = 'general';
            $params = "text=".urlencode($inputStr)."&to=".$toLanguage."&from=".$fromLanguage;
            $translateUrl = "http://api.microsofttranslator.com/v2/Http.svc/Translate?$params";
            //Create the Translator Object.
            $translatorObj = new HTTPTranslator();
            //Get the curlResponse.
            $curlResponse = $translatorObj->curlRequest($translateUrl, $authHeader);
            //Interprets a string of XML into an object.
            $xmlObj = simplexml_load_string($curlResponse);
            foreach((array)$xmlObj[0] as $val){
                $translatedStr = $val;
            }
            return $translatedStr;
        } catch (Exception $e) {
            return "Exception: " . $e->getMessage() . PHP_EOL;
        }

    }
    /*
    * Create and execute the HTTP CURL request.
    *
    * @param string $url        HTTP Url.
    * @param string $authHeader Authorization Header string.
    * @param string $postData   Data to post.
    *
    * @return string.
    *
    */
    function curlRequest($url, $authHeader, $postData=''){
        //Initialize the Curl Session.
        $ch = curl_init();
        //Set the Curl url.
        curl_setopt ($ch, CURLOPT_URL, $url);
        //Set the HTTP HEADER Fields.
        curl_setopt ($ch, CURLOPT_HTTPHEADER, array($authHeader,"Content-Type: text/xml"));
        //CURLOPT_RETURNTRANSFER- TRUE to return the transfer as a string of the return value of curl_exec().
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
        //CURLOPT_SSL_VERIFYPEER- Set FALSE to stop cURL from verifying the peer's certificate.
        curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, False);
        if($postData) {
            //Set HTTP POST Request.
            curl_setopt($ch, CURLOPT_POST, TRUE);
            //Set data to POST in HTTP "POST" Operation.
            curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
        }
        //Execute the  cURL session.
        $curlResponse = curl_exec($ch);
        //Get the Error Code returned by Curl.
        $curlErrno = curl_errno($ch);
        if ($curlErrno) {
            $curlError = curl_error($ch);
            throw new Exception($curlError);
        }
        //Close a cURL session.
        curl_close($ch);
        return $curlResponse;
    }
    public static function get_domain_lang()
    {
        $domain = str_replace('www.','',$_SERVER['SERVER_NAME']);

        if($domain == 'localhost') $domain = "udnmovies.info"; //test

        $domains['udnmovies.info'] = "en";
        $domains['getmovielinks.com'] = "en";
        $domains['earnmovie.com'] = "en";
        $domains['moviezfind.com'] = "en";
        $domains['moviezhunt.com'] = "en";
        $domains['ttmoviez.com'] = "en";
        $domains['udnmovies.com'] = "ar"; //arabic

        //return $domains[$domain];
		
		return $domain == 'udnmovies.com' ? 'ar' : 'en';
    }
}
class AccessTokenAuthentication {
    /*
     * Get the access token.
     *
     * @param string $grantType    Grant type.
     * @param string $scopeUrl     Application Scope URL.
     * @param string $clientID     Application client ID.
     * @param string $clientSecret Application client ID.
     * @param string $authUrl      Oauth Url.
     *
     * @return string.
     */
    function getTokens($grantType, $scopeUrl, $clientID, $clientSecret, $authUrl){
        try {
            //Initialize the Curl Session.
            $ch = curl_init();
            //Create the request Array.
            $paramArr = array (
                'grant_type'    => $grantType,
                'scope'         => $scopeUrl,
                'client_id'     => $clientID,
                'client_secret' => $clientSecret
            );
            //Create an Http Query.//
            $paramArr = http_build_query($paramArr);
            //Set the Curl URL.
            curl_setopt($ch, CURLOPT_URL, $authUrl);
            //Set HTTP POST Request.
            curl_setopt($ch, CURLOPT_POST, TRUE);
            //Set data to POST in HTTP "POST" Operation.
            curl_setopt($ch, CURLOPT_POSTFIELDS, $paramArr);
            //CURLOPT_RETURNTRANSFER- TRUE to return the transfer as a string of the return value of curl_exec().
            curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
            //CURLOPT_SSL_VERIFYPEER- Set FALSE to stop cURL from verifying the peer's certificate.
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            //Execute the  cURL session.
            $strResponse = curl_exec($ch);
            //Get the Error Code returned by Curl.
            $curlErrno = curl_errno($ch);
            if($curlErrno){
                $curlError = curl_error($ch);
                throw new Exception($curlError);
            }
            //Close the Curl Session.
            curl_close($ch);
            //Decode the returned JSON string.
            $objResponse = json_decode($strResponse);
            if ($objResponse->error){
                throw new Exception($objResponse->error_description);
            }
            return $objResponse->access_token;
        } catch (Exception $e) {
            echo "Exception-".$e->getMessage();
        }
    }
}
/*
 * Class:HTTPTranslator
 *
 * Processing the translator request.
 */
Class HTTPTranslator {
    /*
     * Create and execute the HTTP CURL request.
     *
     * @param string $url        HTTP Url.
     * @param string $authHeader Authorization Header string.
     * @param string $postData   Data to post.
     *
     * @return string.
     *
     */
    function curlRequest($url, $authHeader) {
        //Initialize the Curl Session.
        $ch = curl_init();
        //Set the Curl url.
        curl_setopt ($ch, CURLOPT_URL, $url);
        //Set the HTTP HEADER Fields.
        curl_setopt ($ch, CURLOPT_HTTPHEADER, array($authHeader,"Content-Type: text/xml"));
        //CURLOPT_RETURNTRANSFER- TRUE to return the transfer as a string of the return value of curl_exec().
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
        //CURLOPT_SSL_VERIFYPEER- Set FALSE to stop cURL from verifying the peer's certificate.
        curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, False);
        //Execute the  cURL session.
        $curlResponse = curl_exec($ch);
        //Get the Error Code returned by Curl.
        $curlErrno = curl_errno($ch);
        if ($curlErrno) {
            $curlError = curl_error($ch);
            throw new Exception($curlError);
        }
        //Close a cURL session.
        curl_close($ch);
        return $curlResponse;
    }
}


